<?php
class dbli{
    /* 数据库链接 */
    public $con;
    /* 构造方法连接数据库 */
    public function __construct($conf) {
        $con=new mysqli( $conf ['DBhost'], $conf ['DBname'], $conf ['DBpasswd'],$conf ['DBbase'],3306);
        mysqli_query($con, 'set names utf8');
        $this->con = $con;
    }
    
    /* count */
    public function count($sql) {
        $query =mysqli_query($this->con, $sql);
        $result=  mysqli_fetch_array($query);
        return $result [0];
    }
    
    /* 数据库添加方法 */
    public function add($sql) {
        mysqli_query($this->con, $sql);
        $rc = mysqli_affected_rows($this->con);
        if ($rc > 0) {
            return mysqli_insert_id( $this->con );
        } else {
            return 0;
        }
    }
    
    /* mysql 查询 */
    public function select($sql) {
        $result =  mysqli_query($this->con, $sql);
        while ( $row =@ mysqli_fetch_assoc( $result ) ) {
            $arr [] = $row;
        }
        return $arr;
    }
    
    /* mysql 增改 */
    public function U_D($sql) {
        $result = mysqli_query($this->con, $sql);
        return mysqli_affected_rows ( $this->con );
    }
    /* 获取mysql 错误 */
    public function error() {
        return $this->con->error;
    }
    
}